From: Richard M. Stallman Date: Fri, 31 Dec 1993 09:25:12 +0000 (+0000) Subject: (shell-quote-argument): New function. X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1^2~5^2~93675 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=8af7df607d2e0cdf57791cfe107626918b028ed4;p=emacs.git (shell-quote-argument): New function. --- diff --git a/lisp/subr.el b/lisp/subr.el index 9d6e4ac3228..fce4a56e79b 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -643,6 +643,18 @@ Wildcards and redirection are handle as usual in the shell." (cons 'progn body) (list 'store-match-data original))))) +(defun shell-quote-argument (argument) + "Quote an argument for passing as argument to an inferior shell." + ;; Quote everything except POSIX filename characters. + ;; This should be safe enough even for really weird shells. + (let ((result "") (start 0) end) + (while (string-match "[^---0-9a-zA-Z_./]" argument start) + (setq end (match-beginning 0) + result (concat result (substring argument start end) + "\\" (substring argument end (1+ end))) + start (1+ end))) + (concat result (substring argument start)))) + ;; now in fns.c ;(defun nth (n list) ; "Returns the Nth element of LIST.